<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" type="text/css" href="__CSS__/main.css" />
    <link rel="stylesheet" type="text/css" href="__CSS__/common.css" />
    <link rel="stylesheet" type="text/css" href="__CSS__/bootstrap.min.css" />
    <script type="text/javascript" src="__EXTEND__/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="__EXTEND__/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="__EXTEND__/lib/layer/2.4/layer.js"></script>
    <![endif]-->
    <title></title>
</head>
<body>
<div class="contant">
<div class="row">
    <div class="top">资产部>逾期指派</div>
    <div class="content applylist">
        <div class="box">
            <h1>逾期指派列表</h1>
            <div class="list-block">
                <div class="row">
                    <a href="{:U('Task/add')}"><button class="btn btn-primary">导入逾期报表</button></a>
                    <a href="{:U('Task/addUrge')}"><button class="btn btn-primary">代偿报表导入</button></a>
                    <a class="mass" href="javascript:void(0)"><button class="btn btn-warning">群发催收</button></a>
                </div>
                <div class="row">
                    <table class="list">
                        <tr>
                            <th class="center"><input class="check-all" type="checkbox" value=""></th>
                            <th>姓名</th> <th>身份证</th><th>手机号</th><th>银行卡号</th> <th>逾期月份</th> <th>逾期金额</th><th>指派对象</th><th>状态</th><th>操作</th>
                        </tr>
                        <volist name="list" id="_overdue">
                            <tr id="overdue{$_overdue.id}">
                                <td class="center">
                                    <if condition="$_overdue['user_id'] neq 1"><input class="uids" type="checkbox"
                                                                             name="uids[]"
                                                                             value="{$_overdue['user_id']}">
                                        <else/>
                                        <span title="系统管理员，禁止删除">--</span></if>
                                </td>
                                <td>{$_overdue.user_name}</td>
                                <td>{$_overdue.indenty_no}</td>
                                <td>{$_overdue.telephone}</td>
                                <td>{$_overdue.bank_card}</td>
                                <td>{$_overdue.overdue_month}</td>
                                <td>{$_overdue.overdue_money}</td>
                                <td id="task{$_overdue.id}">
                                    {$_overdue.name}
                                </td>
                                <td>

                                    <switch name="_overdue.task_status" >
                                        <case value="0"> 未催回</case>
                                        <case value="1"> 已催回</case>
                                        <case value="2"> 已代偿</case>
                                    </switch>
                                </td>
                                <td>
                                    <a class="point-task" data-id={$_overdue.id} data-toggle="modal" data-target="#pointTask" href="##">指派</a>
                                    <a href="{:U('task/log?indenty_no='.$_overdue['indenty_no'].'&overdue_id='.$_overdue['id'])}">查看反馈</a>
                                    <!--<a class="finish-task" href="##" data-id={$_overdue['id']}>完成指派</a>-->
                                </td>
                            </tr>
                        </volist>
                    </table>
                </div>
                {$page}
            </div>
        </div>
    </div>
</div>
</div>

<!-- Modal -->
<div class="modal fade" id="pointTask" tabindex="-1" role="dialog" aria-labelledby="pointTaskLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="pointTaskLabel">指派任务</h4>
      </div>
      <div class="modal-body">
        <div id="bank_select">
            <label>指派对象:</label>
            <select id="point-obj" name="task_status" class="form-control">
                <option value=1>电催</option>
                <option value=2>外催</option>
                <option value=3>法务</option>
            </select>
            <input type="hidden" id="overdue-id">
        </div>
      </div>

      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">取消指派</button>
        <button id="query-point" type="button" class="btn btn-primary">确认指派</button>
      </div>
    </div>
  </div>
</div>

<script type="text/javascript">

    $('.mass').click(function() {
        if (confirm('你确定要群发催收短信吗？')) {
            $.ajax({
               type: "POST",
               url: "__URL__/mass",
               data: {},
               success: function(msg){
                    console.log(msg);
                    alert('群发完成');
               }
            });
        }
    });

    $(".check-all").click(function () {
        $(".uids").prop("checked", this.checked);
    });
    $(".uids").click(function () {
        var option = $(".uids");
        option.each(function (i) {
            if (!this.checked) {
                $(".check-all").prop("checked", false);
                return false;
            } else {
                $(".check-all").prop("checked", true);
            }
        });
    });

    // 完成指派任务
    $('.finish-task').click(function(){
        if (confirm('确认该逾期完成指派吗？')) {
            var overdue_id = $(this).attr('data-id');

            $.ajax({
               type: "POST",
               url: "__URL__/finishTask",
               data: {
                    overdue_id:overdue_id
                },
               success: function(msg){
                    console.log(msg);
                    if (msg == 1) {
                        alert('操作完成');
                        $('#overdue'+overdue_id).remove();
                        return false;
                    }else{
                        msg = $.parseJSON(msg);
                        alert(msg.message);
                    }
               }
            });

        }
    });

    // 传递overdue-id
    $('.point-task').click(function(){
        var overdueId = $(this).attr('data-id');
        $('#overdue-id').val(overdueId);
    });

    // 提交指派对象
    $('#query-point').click(function(){
        var overdueId = $('#overdue-id').val();
        var taskObj   = $('#point-obj').val();
        var objName   = $("#point-obj").find("option:selected").text();

        $.ajax({
           type: "POST",
           url: "__URL__/pointTask",
           data: {
                overdue_id:overdueId,
                task_status:taskObj
            },
           success: function(msg){
                console.log(msg);
                if (msg == 1) {
                    alert('指派成功');
                    $('#task'+overdueId).html(objName);
                    return false;
                }else{
                    msg = $.parseJSON(msg);
                    alert(msg.message);
                }
           }
        });

        $(this).attr('data-dismiss','modal');
    });
</script>
</body>
</html>